<? include ("../init.php") ?>
<? include ("../header.php") ?>
<? include ("../menu.php") ?>
<? include ("submenu.php") ?>

<?php
  $sql = 'SELECT * FROM project_cat ORDER BY project_cat_name';
  $rss = $db->query($sql);
  $select_cat = '<select name = "catalogue" class = "nput size1" >';
  while ($line2 = $db->fetchNextObject($rss)){
    $select_cat .= "<option value = '".$line2->project_cat_id."'>".$line2->project_cat_name."</option>";
  }
  $select_cat .= "</select>";

  //$select_year = "<select name = 'year' class = 'nput size1' >";
  //
  //  for($i=date("Y"); $i>date("Y")-80;$i--) {
  //    $select_year .= "<option value = '".$i."'>".$i."</option>";
  //  }
  //$select_year .= "</select>";
?>

<div id = "body">

<h1>+<?_l('add')?> <?_l('project')?></h1>
<div class = "clear"></div>


<form method="post" action="add2.php" target="ajaxIfrm" class = "form" enctype="multipart/form-data">
  <div class = "field"><label><?_l('catalogue')?></label><?php echo $select_cat; ?></div>
  <div class = "field"><label><?_l('name')?></label><input type = "text" name = "name" class = "input size1" ></div>
  <div class = "field"><label><?_l('date')?></label><input type = "text" name = "date" class = "input size1" id="datepicker"></div>
  <div class = "field"><label><?_l('area')?></label><input type = "text" name = "area" class = "input size1" ></div>
  <div class = "field"><label><?_l('owner')?></label><input type = "text" name = "owner" class = "input size1" ></div>
  <!--<div class = "field"><label><?_l('complete-year')?></label><?php echo $select_year; ?></div>-->
  <div class = "field"><label><?_l('complete-year')?></label><input type = "text" name = "year" class = "input size1" ></div>
  <div class = "field"><label><?_l('value')?></label><input type = "text" name = "value" class = "input size1" ></div>
  <div class = "field"><label><?_l('image')?></label><input type = "file" name = "img" class = "input size1" ></div>
  <div class = "field"><label><?_l('certificate')?></label><input type = "file" name = "cert" class = "input size1" ></div>
  
   <div class = "field">
    <label><?_l('gallery')?></label>
    <input type="file" id="file_upload" name="file_upload" />
  </div>
   
  <hr>
  <div class = "field"><label></label><input type = "submit" value = "<?=__l('add')?>" class = "btn">&nbsp;<a href = "#" class = "btn" onclick="javascript:history.back(1)"><?_l('cancel')?></a></div>
</form>

</div>
<iframe class="hiddenEle" name="ajaxIfrm"></iframe>
<style>
  .form label {
    width:80px;
  }
</style>
<link href="../js/jquery.uploadify/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.uploadify/swfobject.js"></script>
<script type="text/javascript" src="../js/jquery.uploadify/jquery.uploadify.v2.1.4.min.js"></script>
<script>
  $(document).ready(function(){
    $('#datepicker').datepicker({
      dateFormat: 'yy-mm-dd',
      changeMonth: true,
      changeYear: true
    });
  });
  
  function uploadify_(projectid){
    if(queueSize!=0){
      $('#file_upload').uploadifySettings('scriptData', { 'pid' :  projectid});
      $('#file_upload').uploadifyUpload();
    }else{
      window.location='edit.php?aid='+projectid;
    }
  }
  
  var queueSize = 0;
  
  $('#file_upload').uploadify({
    'uploader'    : '../js/jquery.uploadify/uploadify.swf',
    'script'      : 'uploadify.php',
    'cancelImg'   : '../js/jquery.uploadify/cancel.png',
    'fileDataName':'projectfiles',
    'fileExt'        : '*.jpg;*.gif;*.png',
    'fileDesc'       : 'Image Files (.JPG, .GIF, .PNG)',
    'buttonText'  : 'Browse...',
    'multi'       : true,
    onCancel: function (a, b, c, d) {
        queueSize = d.fileCount;
    },
    onClearQueue: function (a, b) {
        queueSize = b.fileCount;
    },
    onSelectOnce: function (a, b) {
        queueSize = b.fileCount;
    },
    onAllComplete: function () {      
        queueSize = 0;
    },
    onComplete: function (a, b ,c, d, e) {
        queueSize = 0;
    },
    'onAllComplete' : function(e,d){
      if(d==0)
      {
        alert('Image(s) can\'t be uploaded, please check and edit again later.');
      }
      setInterval("window.location='edit.php';",1000);
    }
  });
</script>
</div>
<? include "../footer.php" ?>